<template> 
  <section class="component case-verified">
    <el-form :model="model" :rules="rules" ref="verify-form" label-width="90px">
      <el-form-item label="核销说明" prop="description">
        <el-input type="textarea" v-model="model.description" :maxlength="500"></el-input>
      </el-form-item>
    </el-form>
    <div class="operate-buttons">
      <el-button @click="close">取消</el-button>
      <el-button @click="commit">提交</el-button>
    </div>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies } from "~/core/decorator";
import { State, Action, Getter } from "vuex-class";
import { Emit, Prop, Watch } from "vue-property-decorator";
import { Form } from "element-ui";
import { CaseVerifyService } from "~/services/domain-service/case-verify.service";

@Component({
  components: {}
})
export default class CaseVerified extends Vue {
  @Dependencies(CaseVerifyService)
  private caseVerifyService: CaseVerifyService;
  @Prop({required: true, default: []}) private selectionList 

  private model: any = {
    description: "",
  };
  
  //数据校验
  private rules: any = {
    description: [
      { required: true, message: "请输入申请说明", trigger: "blur" },
      { max: 500, message: "备注不能超过500字符", trigger: "blur"}
    ],
  };
  
  @Emit("refreshData")
  private refreshData() {}
  @Emit("close")
  private close() {}

  /**
   * 提交验证并并与数据库交互
   */
  private commit() {
    const verifyForm: any = this.$refs["verify-form"];
    verifyForm.validate(valid => {
      if (!valid) return
      const caseIds = this.selectionList.map(v => v.id)
      const params = {...this.model, caseIds}
      this.caseVerifyService.verifiedCaseInfo(params)
        .subscribe((data) => {
          this.$message.success('批量核销成功')
          this.refreshData()
          this.close()
        })
    })
  }

  /**
   * 重置方法
   */
  private refresh() {
    const verifyForm: any = this.$refs["verify-form"]
    verifyForm.resetFields()
  }
}
</script>

<style lang="less" scoped>
</style>
